package com.yy.controller;

import com.yy.clientEntities.TestData;
import com.yy.service.TestDataService;
import com.yy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

/**
 * Author young
 * Date 2023/1/3 23:11
 * Description: SpringCloudAlibaba
 */
@RestController
@RequestMapping("nacos1")
public class TestController {
    @Autowired
    private TestDataService testDataService;
    @Value("${server.port}")
    private String port;
    @PutMapping("add")
    public Result<String> add(@RequestBody TestData testData){
       return Result.ok(testDataService.add(testData)).message("->端口号为"+port);
    }
    @DeleteMapping("delete/{id}")
    public Result<String> delete(@PathVariable("id")Integer id){
        return Result.ok(testDataService.delete(id)).message("->端口号为"+port);
    }
    @PostMapping("update")
    public Result<TestData> update(@RequestBody TestData testData){
        return Result.ok(testDataService.update(testData)).message("->端口号为"+port);
    }
    @GetMapping("find/{id}")
    public Result<TestData> findOne(@PathVariable("id")Integer id){
        return Result.ok(testDataService.findOne(id)).message("->端口号为"+port);
    }
    @GetMapping("all")
    public Result<Collection<TestData>> all(){
        return Result.ok(testDataService.findAll()).message("->端口号为"+port);
    }
}
